/**
 * Created by liuzengrong on 2019/8/16.
 */
import React from 'react';
import { connect } from 'dva';
import { message } from 'antd';
import StandardModule from '@/components/hyperspace/modules/StandardModule';

/**
 * 自定义模块
 */
// @ts-ignore
const LocalModule: React.FC = ({ standardModuleExample, dispatch }) => (
  <StandardModule
    data={standardModuleExample.data}
    config={{
      common: {
        formItemOptions: {
          costObject: {
            rules: [{ required: true, message: '该字段不能为空！' }],
          },
          costSubject: {
            rules: [{ required: true, message: '该字段不能为空！' }],
          },
          costType: {
            rules: [{ required: true, message: '该字段不能为空！' }],
          },
          currency: {
            rules: [{ required: true, message: '该字段不能为空！' }],
          },
        },
      },
      search: {
        fields: ['costObject', 'costSubject', 'costType'], // 查询条件
        tabs: {
          field: 'status',
          tabItems: [
            {
              title: '全部',
              value: '',
              active: true,
            },
            {
              title: '待审核',
              value: 'TO_AUDIT',
            },
            {
              title: '审核通过',
              value: 'AUDIT_PASS',
            },
            {
              title: '审核失败',
              value: 'AUDIT_FAIL',
            }
          ],
        }, // 状态栏
      },
      list: {
        url: '/api/record/query',
        fields: [
          'id',
          'costObject',
          'costSubject',
          'costType',
          'currency',
          'singlePrice',
          'number',
          'rate',
          'creator',
          'creatTime'
        ], // 列表字段
        format: {
          username: {
            render: (value: any) => `格式化 - ${value}`,
          },
        },
        extensions: {
          operations: [
            (record: any) => (
              <a
                onClick={() => {
                  message.info(`审核：${JSON.stringify(record)}`);
                }}
              >
                审核
              </a>
            ),
          ],
        },
      },
      add: {
        url: '/api/record/create',
        // width: 680, // 非必填，默认680px
        // title: '新建表单', // 非必填，默认`新建`
        fields: ['costObject', 'costSubject', 'costType', 'currency', 'singlePrice', 'number', 'rate'], // 新增表单字段
      },
      update: {
        url: '/api/record/update',
        // width: 680, // 非必填，默认680px
        // title: '新建表单', // 非必填，默认`新建`
        fields: ['costObject', 'costSubject', 'costType', 'currency', 'singlePrice', 'number', 'rate'], // 修改表单字段
        primaryKeys: ['id'], // 主键字段列表
      },
      delete: {
        url: '/api/record/remove',
        batchDelete: true, // 是否开启批量删除
        fields: ['id'], // 删除依据字段
        batchDeleteUrl: '/api/record/batchDelete',
      },
    }}
    namespace="standardModuleExample"
    dispatch={dispatch}
  />
);

// @ts-ignore
export default connect(({ standardModuleExample }) => ({
  standardModuleExample,
}))(LocalModule);
